#include <drivers/uart.h>
#include <drivers/irq.h>
#include <kernel/initcall.h>
#include <kernel/syslog.h>
#include <kernel/shell.h>
#include <drivers/gpio.h>


static void system_uart_handler(void *data)
{
    shell_token_handler();
}


static int system_shell_probe(struct uart_device *dev)
{
    irq_request(dev->irq_num, system_uart_handler, NULL);

    irq_enable(dev->irq_num);

    syslog_bind_uart_device(dev);
    shell_bind_uart_device(dev);

    uart_put_string(shell_device(), "\r\n");
    return 0;
}


static struct of_device_id console_match[] = {
    {.compatible = "system-shell", },
    { }
};


static struct uart_driver console = {
    .driver = {
        .name = "system-shell",
        .of_match_table = console_match,
    },
    .probe = system_shell_probe,
    .remove = NULL,
};


static int system_shell_init(void)
{
    uart_driver_register(&console);
    
    return 0;
}


core_initcall(system_shell_init);
